package com.api.shopapi.service.impl;

import com.api.shopapi.entity.RechargeInfo;
import com.api.shopapi.entity.User;
import com.api.shopapi.entity.dto.ElderlyDTO;
import com.api.shopapi.mapper.ElderlyMapper;
import com.api.shopapi.mapper.ExportOldestMapper;
import com.api.shopapi.mapper.UserMapper;
import com.api.shopapi.service.ExportOldestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service("ExportOldestServiceImplOne")
public class ExportOldestServiceImpl implements ExportOldestService {

    @Autowired
    private ExportOldestMapper exportOldestMapper;

    @Autowired
    private ElderlyMapper elderlyMapper;

    @Autowired
    private UserMapper userMapper;


    @Override
    public List<RechargeInfo> getForRechargeInfo(String rechargeGroupCode) {
        List<RechargeInfo> rechargeInfoList1=new ArrayList<>();
        List<RechargeInfo> rechargeInfoList=exportOldestMapper.getForRechargeInfo(rechargeGroupCode);
        for (RechargeInfo rechargeInfo:rechargeInfoList){
            ElderlyDTO elderlyDTO =elderlyMapper.getByElderlyCode(rechargeInfo.getElderlyCode());
            User user =userMapper.getByUserCode(elderlyDTO.getUserCode());
            RechargeInfo rechargeInfo1 =RechargeInfo.builder().name(rechargeInfo.getName()).elderlyName(elderlyDTO.getName()).idCard(elderlyDTO.getIdCard()).phone(user.getPhone()).createTime(rechargeInfo.getCreateTime()).money(rechargeInfo.getAddBalance()).build();
            rechargeInfoList1.add(rechargeInfo1);
        }
        return rechargeInfoList1;
    }
}
